package com.exam.alibaba;

/**
 * date:
 * description:
 */
public class Solution004 {
    public static void main(String[] args) {
        String A = "ABCD";
        String B = "*C*";
        boolean match = isMatch(A, B);
        System.out.println(match);
    }

    public static boolean isMatch(String str, String pattern){
        String[] subs = pattern.split("\\*");
        int len = subs.length;
        int index = 0;
        if(!pattern.startsWith("*") && str.indexOf(subs[0], index) != 0){
            return false;
        }
        for (int i = 0; i < len; i++) {
            int ind = str.indexOf(subs[i], index);
            if(ind == -1){
                return false;
            }
            index = ind + subs[i].length();
        }
        if(pattern.charAt(pattern.length() - 1) == '*'){
            return true;
        }
        return index == str.length();
    }

}
